CSS Multiple Columns

    This CSS tutorial will be learning how to set multiple columns layout for element content. Multiple columns help us to divide the content of an element into multiple sections. This article has mentioned different CSS properties, which can help us in creating a multi-column layout.

    Multi-column Properties

    In this tutorial, we will explore these multi-column properties.

    • column-count
    • column-gap
    • column-rule-style
    • column-rule-width
    • column-rule-color
    • column-rule
    • column-span
    • column-width

    Create Multi-Columns using column-count Property

    To create a multi-column text, we can use the column-count property. This property divides the element into specified columns counts.

    Example

    Let’s divide a <div> element text into three columns

    <!DOCTYPE  html>
    <html>
    <head>
        <title></title>
        <style>
            .multi{
                column-count: 3;
            }
        </style>
    </head>
    <body>
    
    <div class="multi"> cived rehtona no neve - ffo tfel uoy erehw srebmemer droW ,dne eht hcaer uoy erofeb gnidaer pots ot deen uoy fI .tnaw uoy txet eht no sucof dna tnemucod eht fo strap espalloc nac uoY .weiv gnidaeR wen eht ni ,oot ,reisae si gnidaeR
    .ngis sulp eht kcilc neht dna ,nmuloc a ro wor a dda ot tnaw uoy erehw kcilc ,elbat a no krow uoy nehW .ti ot txen sraeppa snoitpo tuoyal rof nottub a dna ti kcilc ,tnemucod ruoy ni stif erutcip a yaw eht egnahc oT .meht deen uoy erehw pu wohs taht snottub wen htiw droW ni emit evaS
    .emeht wen eht hctam ot egnahc sgnidaeh ruoy ,selyts ylppa uoy nehW .emeht wen ruoy hctam ot egnahc scihparg trAtramS dna ,strahc ,serutcip eht ,emehT wen a esoohc dna ngiseD kcilc uoy nehW .detanidrooc tnemucod ruoy peek pleh osla selyts dna semehT
    .seirellag tnereffid eht morf tnaw uoy stnemele eht esoohc neht dna tresnI kcilC .rabedis dna ,redaeh ,egap revoc gnihctam a dda nac uoy ,elpmaxe roF .rehto hcae tnemelpmoc taht sngised xob txet dna ,egap revoc ,retoof ,redaeh sedivorp droW ,decudorp yllanoisseforp kool tnemucod ruoy ekam oT
    .tnemucod ruoy stif tseb taht oediv eht rof enilno hcraes ot drowyek a epyt osla nac uoY .dda ot tnaw uoy oediv eht rof edoc debme eht ni etsap nac uoy ,oediV enilnO kcilc uoy nehW .tniop ruoy evorp uoy pleh ot yaw lufrewop a sedivorp oediV    </div>
    </body>
    </html>

    Set the gap between the Columns

    After mentioning the column-count the text content of the element divides into multiple columns, and a gap sperate those columns. To manipulate the gap space, we can use the column-gap property.

    Example

    This example specifies a gap of 50 pixels between the columns.

    <!DOCTYPE  html>
    <html>
    <head>
        <title></title>
        <style>
            .multi{
                column-count: 3;
                column-gap: 50px;
            }
        </style>
    </head>
    <body>
        <div class="multi"> cived rehtona no neve - ffo tfel uoy erehw srebmemer droW ,dne eht hcaer uoy erofeb gnidaer pots ot deen uoy fI .tnaw uoy txet eht no sucof dna tnemucod eht fo strap espalloc nac uoY .weiv gnidaeR wen eht ni ,oot ,reisae si gnidaeR
              ngis sulp eht kcilc neht dna ,nmuloc a ro wor a dda ot tnaw uoy erehw kcilc ,elbat a no krow uoy nehW .ti ot txen sraeppa snoitpo tuoyal rof nottub a dna ti kcilc ,tnemucod ruoy ni stif erutcip a yaw eht egnahc oT .meht deen uoy erehw pu wohs taht snottub wen htiw droW ni emit evaS
              emeht wen eht hctam ot egnahc sgnidaeh ruoy ,selyts ylppa uoy nehW .emeht wen ruoy hctam ot egnahc scihparg trAtramS dna ,strahc ,serutcip eht ,emehT wen a esoohc dna ngiseD kcilc uoy nehW .detanidrooc tnemucod ruoy peek pleh osla selyts dna semehT
              seirellag tnereffid eht morf tnaw uoy stnemele eht esoohc neht dna tresnI kcilC .rabedis dna ,redaeh ,egap revoc gnihctam a dda nac uoy ,elpmaxe roF .rehto hcae tnemelpmoc taht sngised xob txet dna ,egap revoc ,retoof ,redaeh sedivorp droW ,decudorp yllanoisseforp kool tnemucod ruoy ekam oT
              tnemucod ruoy stif tseb taht oediv eht rof enilno hcraes ot drowyek a epyt osla nac uoY .dda ot tnaw uoy oediv eht rof edoc debme eht ni etsap nac uoy ,oediV enilnO kcilc uoy nehW .tniop ruoy evorp uoy pleh ot yaw lufrewop a sedivorp oediV    
        </div>
    </body>
    </html>

    Set a rule line between the Columns

    With the help of a column-rule-style property, we can draw a vertical line between the columns. And like the border-style the rule can be solid, dotted, or dashed.

    Example

    <!DOCTYPE  html>
    <html>
    <head>
        <title></title>
        <style>
            .multi{
                column-count: 3;
                column-gap: 50px;
                column-rule-style:dashed;
            }
        </style>
    </head>
    <body>
        <div class="multi"> cived rehtona no neve - ffo tfel uoy erehw srebmemer droW ,dne eht hcaer uoy erofeb gnidaer pots ot deen uoy fI .tnaw uoy txet eht no sucof dna tnemucod eht fo strap espalloc nac uoY .weiv gnidaeR wen eht ni ,oot ,reisae si gnidaeR
                           ngis sulp eht kcilc neht dna ,nmuloc a ro wor a dda ot tnaw uoy erehw kcilc ,elbat a no krow uoy nehW .ti ot txen sraeppa snoitpo tuoyal rof nottub a dna ti kcilc ,tnemucod ruoy ni stif erutcip a yaw eht egnahc oT .meht deen uoy erehw pu wohs taht snottub wen htiw droW ni emit evaS
                           egnahc sgnidaeh ruoy ,selyts ylppa uoy nehW .emeht wen ruoy hctam ot egnahc scihparg trAtramS dna ,strahc ,serutcip eht ,emehT wen a esoohc dna ngiseD kcilc uoy nehW .detanidrooc tnemucod ruoy peek pleh osla selyts dna semehT
                           seirellag tnereffid eht morf tnaw uoy stnemele eht esoohc neht dna tresnI kcilC .rabedis dna ,redaeh ,egap revoc gnihctam a dda nac uoy ,elpmaxe roF .rehto hcae tnemelpmoc taht sngised xob txet dna ,egap revoc ,retoof ,redaeh sedivorp droW ,decudorp yllanoisseforp kool tnemucod ruoy ekam oT
                           taht oediv eht rof enilno hcraes ot drowyek a epyt osla nac uoY .dda ot tnaw uoy oediv eht rof edoc debme eht ni etsap nac uoy ,oediV enilnO kcilc uoy nehW .tniop ruoy evorp uoy pleh ot yaw lufrewop a sedivorp oediV    </div>
    </body>
    </html>
    • With the column-rule-width we can specify the width of the rule line.
    • With column-rule-color we can specify the rule color
    • With column-rule we can specify all the above column rules property in a single statement.

    Example CSS:

       {
                column-rule-style:dashed;
                column-rule-color: red;
                column-rule-width: 4px;
            }

    OR

    {column-rule: 4px dashed red;}

    Specify the Span for the divided column

    For some text like heading or footer, we do not want them to divide into multiple columns like the other text content. So we can use the column-span property to define how many columns should the element span across. It accepts the value in number and all. The all value specifies that the element will span all columns.

    Example

    <!DOCTYPE  html>
    <html>
    <head>
        <title></title>
        <style>
            .multi{
                column-count: 3;
                column-gap: 50px;
            }
    
            .multi h2{
                column-span: all;
            }
        </style>
    </head>
    <body>
        <div class="multi">
                 <h2>Head of the content</h2>
                 cived rehtona no neve - ffo tfel uoy erehw srebmemer droW ,dne eht hcaer uoy erofeb gnidaer pots ot deen uoy fI .tnaw uoy txet eht no sucof dna tnemucod eht fo strap espalloc nac uoY .weiv gnidaeR wen eht ni ,oot ,reisae si gnidaeR
                 kcilc neht dna ,nmuloc a ro wor a dda ot tnaw uoy erehw kcilc ,elbat a no krow uoy nehW .ti ot txen sraeppa snoitpo tuoyal rof nottub a dna ti kcilc ,tnemucod ruoy ni stif erutcip a yaw eht egnahc oT .meht deen uoy erehw pu wohs taht snottub wen htiw droW ni emit evaS
                 hctam ot egnahc sgnidaeh ruoy ,selyts ylppa uoy nehW .emeht wen ruoy hctam ot egnahc scihparg trAtramS dna ,strahc ,serutcip eht ,emehT wen a esoohc dna ngiseD kcilc uoy nehW .detanidrooc tnemucod ruoy peek pleh osla selyts dna semehT
                 reffid eht morf tnaw uoy stnemele eht esoohc neht dna tresnI kcilC .rabedis dna ,redaeh ,egap revoc gnihctam a dda nac uoy ,elpmaxe roF .rehto hcae tnemelpmoc taht sngised xob txet dna ,egap revoc ,retoof ,redaeh sedivorp droW ,decudorp yllanoisseforp kool tnemucod ruoy ekam oT
                 stif tseb taht oediv eht rof enilno hcrw R ading vi w. You can collaps  parts of th  docum nt and focus on th  t xt you want. If you n  d to stop r ading b for  you r ach th   nd, Word r m mb rs wh r  you l ft off -  v n on anoth r d vic .
        </div>
    </body>
    </html>

    Set the column width

    The column-width property specifies the width of each column. Like other width property, it can accept relative and absolute length values.

    Example

    <!DOCTYPE  html>
    <html>
    <head>
        <title></title>
        <style>
            .multi{
                column-count: 3;
                column-width:200px;
            }
        </style>
    </head>
    <body>
        <div class="multi">
                           rehtona no neve - ffo tfel uoy erehw srebmemer droW ,dne eht hcaer uoy erofeb gnidaer pots ot deen uoy fI .tnaw uoy txet eht no sucof dna tnemucod eht fo strap espalloc nac uoY .weiv gnidaeR wen eht ni ,oot ,reisae si gnidaeR
                           t dna ,nmuloc a ro wor a dda ot tnaw uoy erehw kcilc ,elbat a no krow uoy nehW .ti ot txen sraeppa snoitpo tuoyal rof nottub a dna ti kcilc ,tnemucod ruoy ni stif erutcip a yaw eht egnahc oT .meht deen uoy erehw pu wohs taht snottub wen htiw droW ni emit evaS
                           egnahc sgnidaeh ruoy ,selyts ylppa uoy nehW .emeht wen ruoy hctam ot egnahc scihparg trAtramS dna ,strahc ,serutcip eht ,emehT wen a esoohc dna ngiseD kcilc uoy nehW .detanidrooc tnemucod ruoy peek pleh osla selyts dna semehT
                           morf tnaw uoy stnemele eht esoohc neht dna tresnI kcilC .rabedis dna ,redaeh ,egap revoc gnihctam a dda nac uoy ,elpmaxe roF .rehto hcae tnemelpmoc taht sngised xob txet dna ,egap revoc ,retoof ,redaeh sedivorp droW ,decudorp yllanoisseforp kool tnemucod ruoy ekam oT
                           taht oediv eht rof enilno hcr th  n w R ading vi w. You can collaps  parts of th  docum nt and focus on th  t xt you want. If you n  d to stop r ading b for  you r ach th   nd, Word r m mb rs wh r  you l ft off -  v n on anoth r d vic .
       </div>
    </body>
    </html>

    CSS columns Property

    The columns property is a shorthand for all the properties column-width and column-count.

    Syntax

    {columns: column-width column-count;}

    Summary

    • The columns property is used to divide the content into multiple columns.
    • The column-count property specifies the number of divided columns.
    • The column-gap property specifies the gap between the columns.
    • The column-rule property draws a vertical line between the columns.
    • The column-width property specifies the width of each column.
    • column-span property specifies how many columns an element can span.
    • columns property is a shorthand for column-width and column-count